package com.ruoyi.hr.controller.hr.attendempmanage.attendChange;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.service.PublicService;
import com.ruoyi.hr.service.attendempmanage.attendChange.AttendChangeService;
import com.ruoyi.hr.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author yuanwei
 * @explain 考勤变动
 * @date 2020/4/26
 */
@Controller
@RequestMapping("/attendEmpManage/AttendChange")
public class AttendChangeController extends BaseController {

    private String prefix = "hr/attendempmanage/attendChange";

    @Autowired
    private AttendChangeService attendChangeSerivce;

    @Autowired
    private PublicService publicService;

    //考勤信息变动

    @GetMapping()
    public String findInfoChangeList() {
        return prefix + "/infoChange";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo findInfoChangeList(@RequestParam Map map) {
        return getDataTable(attendChangeSerivce.findInfoChangeList(map));
    }

    @PostMapping("/procedure")
    @ResponseBody
    public BaseResult procedure(String allId, String allName, String procedure) {
        return publicService.procedure(allId, allName, procedure);
    }

    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        int num = attendChangeSerivce.remove(ids);
        if (num == 0) {
            return error("删除中存在已确认信息，请取消确认后删除！");
        }
        return toAjax(num);
    }

    @GetMapping("/add")
    public String add(ModelMap mmp) {
        mmp.put("atEmpType", attendChangeSerivce.findAtEmpType());
        return prefix + "/addInfoChange";
    }

    @PostMapping("/save")
    @ResponseBody
    public AjaxResult save(@RequestParam Map map) {
        return toAjax(attendChangeSerivce.save(map));
    }

    @PostMapping("/findPerson")
    @ResponseBody
    public Map<String, Object> findPerson(String badge) {
        return attendChangeSerivce.findPerson(badge);
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmp) {
        mmp.put("infoChange", attendChangeSerivce.findInfoChange(id));
        mmp.put("atEmpType", attendChangeSerivce.findAtEmpType());
        return prefix + "/editInfoChange";
    }

    @GetMapping("/history")
    public String findInfoChangeHistory() {
        return prefix + "/infoChangeHistory";
    }

    @PostMapping("/history")
    @ResponseBody
    public TableDataInfo findInfoChangeHistory(@RequestParam Map map) {
        return getDataTable(attendChangeSerivce.findInfoChangeHistory(map));
    }

    //考勤状态变动

    @GetMapping("/status")
    public String findInfoStatusList() {
        return prefix + "/infoStatus";
    }

    @PostMapping("/status")
    @ResponseBody
    public TableDataInfo findInfoStatusList(@RequestParam Map map) {
        return getDataTable(attendChangeSerivce.findInfoStatusList(map));
    }

    @GetMapping("/addStatus")
    public String addStatus(ModelMap mmp) {
        mmp.put("atStatus", attendChangeSerivce.findAtStatus());
        return prefix + "/addInfoStatus";
    }

    @PostMapping("/saveStatus")
    @ResponseBody
    public AjaxResult saveStatus(@RequestParam Map map) {
        return toAjax(attendChangeSerivce.saveStatus(map));
    }

    @GetMapping("/editStatus/{id}")
    public String editStatus(@PathVariable("id") String id, ModelMap mmp) {
        mmp.put("infoChange", attendChangeSerivce.findInfoStatus(id));
        mmp.put("atEmpType", attendChangeSerivce.findAtStatus());
        return prefix + "/editInfoStatus";
    }

    @GetMapping("/statusHistory")
    public String findInfoStatusHistory() {
        return prefix + "/infoStatusHistory";
    }

    @PostMapping("/statusHistory")
    @ResponseBody
    public TableDataInfo findInfoStatusHistory(@RequestParam Map map) {
        return getDataTable(attendChangeSerivce.findInfoStatusHistory(map));
    }
}
